package service

import (
	"day12_30/config"
	"day12_30/internal/api/request"
	"day12_30/internal/models/dao"
	"day12_30/pkg"
)

func CreatePrice(userId int, price request.Price) string {
	rabbitmq := pkg.NewRabbitMQSimple("2208A")
	simple := rabbitmq.PublishSimple(userId, price)
	err := config.DB.Model(&dao.Price{}).Create(&simple).Error
	if err != nil {
		return "估价失败"
	}
	return ""
}

func FindPrice(price *request.FindPrice) (*dao.Price, string) {
	var prices *dao.Price
	err := config.DB.Model(&dao.Price{}).Where("id=?", price.PriceId).Find(&prices).Error
	if err != nil {
		return nil, "查询失败"
	}
	if prices.ID == 0 {
		return nil, "查询失败"
	}
	return prices, ""
}
